package com.mcyy.financemanager.service.impl;

import com.mcyy.financemanager.entity.User;
import com.mcyy.financemanager.mapper.UserMapper;
import com.mcyy.financemanager.service.UserService;
import com.sun.jmx.snmp.Timestamp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceimpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    //方法测试
    public void test() {
        User user= userMapper.seleteall1();
        System.out.println(user.toString());
    }
    //登录
    public Integer getuserbyloginname(String loginName, String password) {
        //获取用户信息 最终返回id
        User user=userMapper.getUserbyloginName(loginName,password);
        if(user!=null){
            return user.getId();
        }else {
            return 0;
        }
    }
    //用户注册
    public int adduser(User user) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        String  str =Long.toString(timestamp.getDateTime());
        String id=str.substring(str.length()-9);
        user.setId(Integer.valueOf(id));
        user.setType(2);
        System.out.println(user);
        int a=userMapper.addone(user);
        return 0;
    }
    //根据用户id获取用户信息
    public User getuserinfobyid(Integer id) {
        User user=userMapper.getuserinfobyid(id);
        return user;
    }
    //获取所用用户信息
    public List<User> getalluser() {
        List<User> users=userMapper.getalluser();
        return users;
    }
    //带分页的用户获取
    public List<User> getuserbypage(Integer limit, Integer index,Integer unamei) {
        List<User> users=userMapper.getuserbypage(limit,index,unamei);
        return users;
    }
    //根据用户id 修改用户
    public int updateuser(User user) {
        int a=userMapper.updateuser(user);
        return 0;
    }
    //根据用户id 删除用户
    public int deleteuserbyid(Integer id) {
        int a=userMapper.deleteuserbyid(id);
        return a;
    }
}
